<?php
/**
 * Created by PhpStorm.
 * User: liyu
 * Date: 2018/4/8
 * Time: 上午10:50
 */

namespace app\common\service;


class Password
{
    static public function getCostVal()
    {
        $cost = 12;
        while(true){
            $startTime = microtime(true);
            password_hash('123456',PASSWORD_BCRYPT,['cost'=>$cost]);
            $endTIme = microtime(true);
            if ($endTIme - $startTime < 0.05) {
//                echo $endTIme - $startTime;
                return $cost;
            }
            $cost--;
        }
    }

    static public function hash($password)
    {
        return password_hash($password,PASSWORD_BCRYPT,['cost'=>8]);
    }

    static public function verify($password,$hash)
    {
        return password_verify($password,$hash);
    }
}